function G_render (){}
$.extend(G_render.prototype,{
    init:function(res){
        this.id = location.hash.substring(1); //哈希值的获取
        var data = this.getdata(res);
        var items = this.render(data);
        return items;
    },
    // 数据的获取  因为有不同的数据写法所以要进行一个判断
    getdata : function(res){
        if(parseInt(this.id) >= 1004){
            res = res.goodslist;
            for(var i = 0, item ; item = res[i] ; i++ ){
                for(var k = 0 ,data ; data = item.goods[k] ; k ++){
                    if(data["dataid"] == this.id){
                        return data;
                    }
                }
            }
        }else{
            res = res.seckilldata;
            // console.log(res);
            for(var i = 0, item ; item = res[i] ; i++ ){
                if(item.dataid == this.id){
                    return item;
                }
            }
        }
    },
    // 渲染部分
    render : function(data){
        // console.log(data)
        var html_nav = "";
        html_nav = `
        <div class="nav_con">
            <a href="../html/index.html">首页</a>
            > 商品详情 > ${data.title}
        </div>
        `
        $(".G_nav").html(html_nav);

        var html_big = `
            <img src="${data.bigimg[0]}" alt="" class="pic">
            <div class="cube"></div>
        `
        $("#big_img").html(html_big);
        var html_img = "";
        for(var i = 0 ,item; item = data.smallimg[i];i++){
            html_img += `
            <li class="small_img">
                <a href="javascript:;">
                    <img src="${item}" alt="" img-id = "${data.bigimg[i]}">
                </a>
            </li>
            `
        }
        $(".pic_list ul").html(html_img);
        $("#goods_id").html(`<h1 class="title">${data.title}</h1>`)
        $(".dec").html(data.subtitle);
        $(".prc_show").html(data.price);
        $(".more_txt").html(data.title);
        var more_img = "";
        for(var k = 0 ,imgs;imgs = data.more[k];k++){
            more_img += `
            <p><img src="${imgs}" alt=""></p>
            `
        }
        $(".more_img").html(more_img);
        return data
    }
})
export default new G_render();